package cn.xhf.export.config;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.xhf.export.core.ExcelCore;
import cn.xhf.export.core.TXTCore;
import cn.xhf.export.index.ExportIndex;
import cn.xhf.export.model.IndexModel;

public class ExportConfig implements ExportIndex{

	public ExcelCore excelCore = new ExcelCore();
	public TXTCore tXTCore = new TXTCore();
	List<String> sqlJoin = new ArrayList<String>();
	List<Map<String, String>> headDataJoin = new  ArrayList<Map<String, String>>();
	
	@Override
	public String initConfig() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see cn.xhf.export.index.ExportIndex#ExportExcel(java.util.Map, java.lang.String)
	 * 基础excel导出
	 */
	@Override
	public File ExportExcel(Map<String, String> headData, String sql) {
		// TODO Auto-generated method stub
		return excelCore.initExcel(headData, sql);
	}

	/* (non-Javadoc)
	 * @see cn.xhf.export.index.ExportIndex#ExportTXT(java.util.Map, java.lang.String)
	 * 导出txt文件
	 */
//	@Override
//	public File ExportTXT(Map<String, String> headData, String sql) {
//		// TODO Auto-generated method stub
//		return tXTCore.initTXTCore(headData, sql, "111");
//	}

	/* (non-Javadoc)
	 * @see cn.xhf.export.index.ExportIndex#ExportMuchExcel(java.util.Map, java.lang.String)
	 * 多个页脚导出
	 */
	@Override
	public File ExportMuchExcel() {
		// TODO Auto-generated method stub
		File file = excelCore.MuchExcel(headDataJoin, sqlJoin);
		sqlJoin.clear();
		headDataJoin.clear();
		return file;
	}

	/* (non-Javadoc)
	 * @see cn.xhf.export.index.ExportIndex#JoinSheetExcel(java.util.Map, java.lang.String)
	 * 多页脚连接
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void JoinSheetExcel(Map<String, String> muchHeadData, String sql) {
		// TODO Auto-generated method stub
		headDataJoin.add((Map<String, String>) muchHeadData);
		sqlJoin.add(sql);
//		return null;
	}

	@Override
	public File ExportFile(Object index) {
		IndexModel indexCore = (IndexModel) index;
		String name = indexCore.getFileName();
		if(name.equals("EXCEL")) {
			// TODO Auto-generated method stub
			if(indexCore.getSqlDATA()==null) {
//				第一种导出
				return excelCore.initExcel(indexCore);
			}else {
				return excelCore.initDataExcel(indexCore);
			}

		}else if(name.equals("TXT")) {
			return tXTCore.initTXTCore(indexCore);
		}else {
				return null;
		}
	}

}
